package com.vilicode.controller;


import com.vilicode.bean.Post;
import com.vilicode.bean.PostType;
import com.vilicode.service.PostService;
import com.vilicode.service.PostTypeService;
import com.vilicode.service.impl.PostTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    public PostService postService;

    @RequestMapping("/index")
    public String init(HttpServletRequest request) {
        Post post = new Post();
        Post post2 = new Post();
        post2.setPname("测试2");
        post2.setImage("https://upload-bbs.miyoushe.com/upload/2023/05/01/301189105/3b112fad1aa62dc2bda3a2fe64fe5643_7164836832745563443.jpg");
        post2.setDescription("测试2");
        post.setPname("测试");
        post.setImage("https://tse2-mm.cn.bing.net/th/id/OIP-C.uuMRp41SjL9ukaBDDBWz5wHaNK?rs=1&pid=ImgDetMain");
        post.setDescription("测试");
        List<Post> posts = new ArrayList<>();
        posts.add(post);
        posts.add(post2);

        request.setAttribute("posts", posts);
        PostType postType = new PostType();
        PostType postType2 = new PostType();
        List<PostType> postTypes = new ArrayList<>();
        postType.setPt_id(1);
        postType.setPtname("计算机");
        System.out.println(postType.getPtname());
        postType2.setPt_id(2);
        postType2.setPtname("教师");
        postTypes.add(postType);
        postTypes.add(postType2);
        request.setAttribute("postTypes", postTypes);
        return "index"; // 返回视图名称
    }

}